package com.tiantianyuegou.http;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * SP工具类
 * Created by George on 2016/8/31.
 */
public class SPHelper {
//    private static SPHelper helper;
    private SharedPreferences settings = null;
    private Context ctx;
    private SharedPreferences.Editor editor;
    private String sPrefsName;

    private static final String scaleRate_W = "scaleRate_W";
    private static final String scaleRate = "scaleRate";

    private static final String TM_ID="tm_id";//会员id
    private static final String TP_ID = "tp_id";//商品id
    private static final String TT_ID="tt_id";//优惠券id
    private static final String TR_ID="tr_id";//红包id
    private static final String TM_GUAN_COUNT="tm_guan_count";//会员贯数
    private static final String TM_RED_COUNT="tm_red_count";//会员红包数
    private static final String TO_ID="to_id";//订单id
    private static final String TM_PHONE="tm_phone";//会员手机号


    private static final String TMD_ID = "tmd_id";

    private static final String TS_ID = "ts_id";//店铺id
    private static final String TF_ID = "tf_id";
    private static final String TD_NAME = "td_name";
    private static final String TD_CODE = "td_code";

    private static final String USERNAME = "username";
    private static final String PASSWORD = "password";

    private static final String ADDRESS = "address";
    private static final String TVCODE="tvCode";

    private static final String AUTOLOGIN="autoLogin";
    private static final String CITY_ID="city_id";

    private static final String TYPE="type";


    public static String getTYPE() {

        return helper.settings.getString(TYPE, "");
    }

    public static void setTYPE(String type) {
        helper.editor.putString(TYPE, type);
        helper.editor.commit();
    }

    //    public static void init(Context context) {
//        helper = new SPHelper(context);
//    }
    public static SPHelper helper;
    public static SPHelper getInstance(Context context) {
        if (helper == null) {
//            throw new NullPointerException(
//                    "NOT INIT sphelper,please call init in app first");
            helper = new SPHelper(context);
        }
        return helper;
    }

    private SPHelper(Context context) {
        this.ctx = context;
        sPrefsName = ctx.getPackageName();
        this.settings = ctx.getSharedPreferences(sPrefsName,
                Context.MODE_PRIVATE);
        this.editor = settings.edit();
    }



    public static String getTmId() {
        return 3+""; //helper.settings.getString(TM_ID, "");
//        return null;
    }

    public static void setTmId(String tm_id) {
        helper.editor.putString(TM_ID, tm_id);
        helper.editor.commit();
    }


    public static String getTPId() {
        return helper.settings.getString(TP_ID, "");
    }

    public static void setTPId(String tp_id) {
        helper.editor.putString(TP_ID, tp_id);
        helper.editor.commit();
    }

    public static String getTSId() {
        return helper.settings.getString(TS_ID, "");
    }

    public static void setTSId(String ts_id) {
        helper.editor.putString(TS_ID, ts_id);
        helper.editor.commit();
    }

//	public static String getTRId() {
//		return getInstance().settings.getString(TR_ID, "");
//	}
//
//	public static void setTRId(String tr_id) {
//		getInstance().editor.putString(TR_ID, tr_id);
//		getInstance().editor.commit();
//	}

    public static String getTmGuanCount() {
        return helper.settings.getString(TM_GUAN_COUNT, "");
    }

    public static void setTmGuanCount(String tm_guan_count) {
        helper.editor.putString(TM_GUAN_COUNT, tm_guan_count);
        helper.editor.commit();
    }

    public static String getTmRedCount() {
        return helper.settings.getString(TM_RED_COUNT, "");
    }

    public static void setTmRedCount(String tm_red_cound) {
        helper.editor.putString(TM_RED_COUNT, tm_red_cound);
        helper.editor.commit();
    }

    public static String getToId() {
        return helper.settings.getString(TO_ID,"");
    }

    public static void setToId(String toId){
        helper.editor.putString(TO_ID, toId);
        helper.editor.commit();
    }

    public static String getTmPhone() {
        return helper.settings.getString(TM_PHONE,"");
    }

    public static void setTmPhone(String tmPhone){
        helper.editor.putString(TM_PHONE, tmPhone);
        helper.editor.commit();
    }



    public static String getTtId() {
        return helper.settings.getString(TT_ID, "");
    }

    public static void setTtId(String tt_id) {
        helper.editor.putString(TT_ID, tt_id);
        helper.editor.commit();
    }

    public static String getTfId() {
        return helper.settings.getString(TF_ID, "0");
    }

    public static void setTfId(String tf_id) {
        helper.editor.putString(TF_ID, tf_id);
        helper.editor.commit();
    }

    public static String getTdName() {
        return helper.settings.getString(TD_NAME, "");
    }

    public static void setTdName(String td_name) {
        helper.editor.putString(TD_NAME, td_name);
        helper.editor.commit();
    }

    public static String getTdCode() {
        return helper.settings.getString(TD_CODE, "");
    }

    public static void setTdCode(String td_code) {
        helper.editor.putString(TD_CODE, td_code);
        helper.editor.commit();
    }

    public static String getUsername() {
        return helper.settings.getString(USERNAME, "");
    }

    public static void setUsername(String username) {
        helper.editor.putString(USERNAME, username);
        helper.editor.commit();
    }

    public static String getPassword() {
        return helper.settings.getString(PASSWORD, "");
    }

    public static void setPassword(String password) {
        helper.editor.putString(PASSWORD, password);
        helper.editor.commit();
    }

    public static String getTmdId() {
        return TMD_ID;
    }

    public static void setTmdId(String tmd_id) {
        helper.editor.putString(TMD_ID, tmd_id);
        helper.editor.commit();
    }

    public static String getAddress() {
        return helper.settings.getString(ADDRESS, "");
    }

    public static void setAddress(String address) {
        helper.editor.putString(ADDRESS, address);
        helper.editor.commit();
    }

    public static String getTvcode() {
        return helper.settings.getString(TVCODE, "");
    }

    public static void setTvcode(String tvcode){
        helper.editor.putString(TVCODE, tvcode);
        helper.editor.commit();
    }

    public static boolean getAutologin() {
        return helper.settings.getBoolean(AUTOLOGIN, false);
    }

    public static void setAutologin(boolean autoLogin){
        helper.editor.putBoolean(AUTOLOGIN, autoLogin);
        helper.editor.commit();
    }

    public static String getCityId() {
        return helper.settings.getString(CITY_ID, "");
    }

    public static void setCityId(String city_id) {
        helper.editor.putString(CITY_ID, city_id);
        helper.editor.commit();
    }
}
